#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N = 2e5 + 10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
int n;
int pre[N], suf[N], st[26];
void solve()
{
	memset(pre, 0, sizeof pre);
	memset(suf, 0, sizeof suf);
	cin >> n;
	string s;
	cin >> s;

	s = " " + s;

	memset(st, 0, sizeof st);
	for (int i = 1; i <= s.size()-1; i++)
	{
		if (st[s[i] - 'a'])
		{
			pre[i] = pre[i - 1];
			continue;
		}
		else
		{
			st[s[i] - 'a'] = 1;
			pre[i] = pre[i - 1] + 1;
		}
	}

	memset(st, 0, sizeof st);
	for (int i = s.size()-1; i >= 1; i--)
	{
		if (st[s[i] - 'a'])
		{
			suf[i] = suf[i + 1];
			continue;
		}
		else
		{
			st[s[i] - 'a'] = 1;
			suf[i] = suf[i + 1] + 1;
		}
	}

	ll ans = -1e9;
	for (int i = 1; i <= s.size() - 1; i++)
	{
		ll t = pre[i] + suf[i + 1];
		ans = max(t, ans);
	}
	cout << ans << '\n';

}

int main()
{
	close();
	int T; cin >> T;
	while (T--) solve();
	return 0;
}